﻿using System;
using UnityEngine;

namespace RootMotion
{
	// Token: 0x020001DE RID: 478
	public class SolverManager : MonoBehaviour
	{
		// Token: 0x060009FE RID: 2558 RVA: 0x000145D5 File Offset: 0x000129D5
		public void Disable()
		{
			Debug.Log("IK.Disable() is deprecated. Use enabled = false instead", base.transform);
			base.enabled = false;
		}

		// Token: 0x060009FF RID: 2559 RVA: 0x000145EE File Offset: 0x000129EE
		protected virtual void InitiateSolver()
		{
		}

		// Token: 0x06000A00 RID: 2560 RVA: 0x000145F0 File Offset: 0x000129F0
		protected virtual void UpdateSolver()
		{
		}

		// Token: 0x06000A01 RID: 2561 RVA: 0x000145F2 File Offset: 0x000129F2
		protected virtual void FixTransforms()
		{
		}

		// Token: 0x06000A02 RID: 2562 RVA: 0x000145F4 File Offset: 0x000129F4
		private void OnDisable()
		{
			if (!Application.isPlaying)
			{
				return;
			}
			this.Initiate();
		}

		// Token: 0x06000A03 RID: 2563 RVA: 0x00014607 File Offset: 0x00012A07
		private void Start()
		{
			this.Initiate();
		}

		// Token: 0x170000C9 RID: 201
		// (get) Token: 0x06000A04 RID: 2564 RVA: 0x0001460F File Offset: 0x00012A0F
		private bool animatePhysics
		{
			get
			{
				if (this.animator != null)
				{
					return this.animator.updateMode == AnimatorUpdateMode.AnimatePhysics;
				}
				return this.legacy != null && this.legacy.animatePhysics;
			}
		}

		// Token: 0x06000A05 RID: 2565 RVA: 0x0001464F File Offset: 0x00012A4F
		private void Initiate()
		{
			if (this.componentInitiated)
			{
				return;
			}
			this.FindAnimatorRecursive(base.transform, true);
			this.InitiateSolver();
			this.componentInitiated = true;
		}

		// Token: 0x06000A06 RID: 2566 RVA: 0x00014677 File Offset: 0x00012A77
		private void Update()
		{
			if (this.skipSolverUpdate)
			{
				return;
			}
			if (this.animatePhysics)
			{
				return;
			}
			if (this.fixTransforms)
			{
				this.FixTransforms();
			}
		}

		// Token: 0x06000A07 RID: 2567 RVA: 0x000146A4 File Offset: 0x00012AA4
		private void FindAnimatorRecursive(Transform t, bool findInChildren)
		{
			if (this.isAnimated)
			{
				return;
			}
			this.animator = t.GetComponent<Animator>();
			this.legacy = t.GetComponent<Animation>();
			if (this.isAnimated)
			{
				return;
			}
			if (this.animator == null && findInChildren)
			{
				this.animator = t.GetComponentInChildren<Animator>();
			}
			if (this.legacy == null && findInChildren)
			{
				this.legacy = t.GetComponentInChildren<Animation>();
			}
			if (!this.isAnimated && t.parent != null)
			{
				this.FindAnimatorRecursive(t.parent, false);
			}
		}

		// Token: 0x170000CA RID: 202
		// (get) Token: 0x06000A08 RID: 2568 RVA: 0x00014750 File Offset: 0x00012B50
		private bool isAnimated
		{
			get
			{
				return this.animator != null || this.legacy != null;
			}
		}

		// Token: 0x06000A09 RID: 2569 RVA: 0x00014772 File Offset: 0x00012B72
		private void FixedUpdate()
		{
			if (this.skipSolverUpdate)
			{
				this.skipSolverUpdate = false;
			}
			this.updateFrame = true;
			if (this.animatePhysics && this.fixTransforms)
			{
				this.FixTransforms();
			}
		}

		// Token: 0x06000A0A RID: 2570 RVA: 0x000147A9 File Offset: 0x00012BA9
		private void LateUpdate()
		{
			if (this.skipSolverUpdate)
			{
				return;
			}
			if (!this.animatePhysics)
			{
				this.updateFrame = true;
			}
			if (!this.updateFrame)
			{
				return;
			}
			this.updateFrame = false;
			this.UpdateSolver();
		}

		// Token: 0x06000A0B RID: 2571 RVA: 0x000147E2 File Offset: 0x00012BE2
		public void UpdateSolverExternal()
		{
			if (!base.enabled)
			{
				return;
			}
			this.skipSolverUpdate = true;
			this.UpdateSolver();
		}

		// Token: 0x0400069A RID: 1690
		[Tooltip("If true, will fix all the Transforms used by the solver to their initial state in each Update. This prevents potential problems with unanimated bones and animator culling with a small cost of performance. Not recommended for CCD and FABRIK solvers.")]
		public bool fixTransforms = true;

		// Token: 0x0400069B RID: 1691
		private Animator animator;

		// Token: 0x0400069C RID: 1692
		private Animation legacy;

		// Token: 0x0400069D RID: 1693
		private bool updateFrame;

		// Token: 0x0400069E RID: 1694
		private bool componentInitiated;

		// Token: 0x0400069F RID: 1695
		private bool skipSolverUpdate;
	}
}
